<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset id="searchFieldset_currentTable" class="table-search-fieldset layui-hide">
            <legend>{:lang("common.condition_search")}</legend>
            <form class="layui-form layui-form-pane form-search">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("contract.number")}</label>
                    <div class="layui-input-inline">
                        <input name="c_number_like" class="layui-input" value="{$param.c_number_like|default=''}"
                               placeholder="{:lang('common.input')}{:lang('contract.number')}">
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("contract.custom_name")}</label>
                    <div class="layui-input-inline">
                        <input name="c_custom_name_like" class="layui-input"
                               value="{$param.c_custom_name_like|default=''}"
                               placeholder="{:lang('common.input')}{:lang('contract.custom_name')}">
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("contract.article")}</label>
                    <div class="layui-input-inline">
                        <input name="c_article_like" class="layui-input" value="{$param.c_article_like|default=''}"
                               placeholder="{:lang('common.input')}{:lang('contract.article')}">
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("contract.status")}</label>
                    <div class="layui-input-inline">
                        <select name="c_status_eq" data-select-type="contract_status_list"
                                data-select-default="{:lang('common.choose')}">
                        </select>
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("contract.signer")}</label>
                    <div class="layui-input-inline">
                        <input name="c_signer_like" class="layui-input" value="{$param.c_signer_like|default=''}"
                               placeholder="{:lang('common.input')}{:lang('contract.signer')}">
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("contract.undertaker")}</label>
                    <div class="layui-input-inline">
                        <input name="c_undertaker_like" class="layui-input"
                               value="{$param.c_undertaker_like|default=''}"
                               placeholder="{:lang('common.input')}{:lang('contract.undertaker')}">
                    </div>
                </div>

                <div class="layui-form-item layui-inline" style="margin-left:50px">
                    <button type="submit" class="layui-btn layui-btn-normal" data-type="tableSearch"
                            lay-submit lay-filter="search_currentTable">{:lang("common.btn_search")}
                    </button>
                </div>
            </form>
        </fieldset>

        <table id="currentTable"
               data-auth-add="{:auth(request()->controller().'/add')}"
               data-auth-edit="{:auth(request()->controller().'/edit')}"
               data-auth-delete="{:auth(request()->controller().'/delete')}"
               data-auth-print="{:auth(request()->controller().'/print')}"
               data-auth-export="{:auth(request()->controller().'/export')}">
        </table>
    </div>
</div>
<script>
    layui.use(['myApp'], function () {
        var myCommon = layui.myCommon;
        window.editContract = function (id) {
            popupWindow('{:lang("contract.see_title")}', 'tally.contract/edit?id=' + id, function () {
                myCommon.api.refreshTable();
            }, 800);
        }

        function getPercent(data, name) {
            let value = myCommon.value(data, name);
            return value == '' ? '' : value + '%';
        }

        myCommon.table.render({
            where: myCommon.generateCondition()
            , limit: "{$param.limit|default='15'}"
            , cols: [[
                {type: "checkbox"}
                , {
                    field: 'number', width: 90, title: '{:lang("contract.number")}', sort: true
                    , templet: myCommon.table.fn, fn: function (value, data) {
                        return '<a onclick="return editContract(' + myCommon.value(data, 'id') + ')">' + value + '</a>';
                    }
                }
                , {field: 'custom_name', minWidth: 100, title: '{:lang("contract.custom_name")}', sort: true}
                , {field: 'article', width: 90, title: '{:lang("contract.article")}', sort: true}
                , {field: 'start_date', width: 90, title: '{:lang("contract.start_date")}', sort: true}
                , {field: 'end_date', width: 90, title: '{:lang("contract.end_date")}', sort: true}
                , {
                    field: 'status', width: 90, title: '{:lang("contract.status")}', sort: true,
                    templet: myCommon.table.type, typeList: 'contract_status_list'
                }
                , {field: 'contract_money', width: 90, title: '{:lang("contract.contract_money_alias")}', sort: true}
                , {
                    field: 'invoice', width: 60, title: '{:lang("contract.invoice")}', sort: true,
                    templet: myCommon.table.type, typeList: 'invoice_status_list'
                }
                , {field: 'invoice_money', width: 90, title: '{:lang("contract.invoice_money")}', sort: true}
                , {field: 'unit', minWidth: 90, title: '{:lang("contract.unit")}', sort: true}
                , {field: 'collect_money', width: 90, title: '{:lang("contract.collect_money")}', sort: true}
                , {field: 'signer', width: 75, title: '{:lang("contract.signer")}', sort: true}
                , {field: 'undertaker', width: 75, title: '{:lang("contract.undertaker")}', sort: true}
                , {
                    field: 'settle', width: 65, title: '{:lang("contract.settle")}'
                    , templet: myCommon.table.fn, fn: function (value, data) {
                        return myCommon.value(data, 'signer') + '<br>' + myCommon.value(data, 'undertaker');
                    }
                }
                , {
                    field: 'settle_rate', width: 75, title: '{:lang("contract.settle_rate")}'
                    , templet: myCommon.table.fn, fn: function (value, data) {
                        return getPercent(data, 'sign_rate') + '<br>' + getPercent(data, 'undertake_rate');
                    }
                }
                , {
                    field: 'settle_money', width: 75, title: '{:lang("contract.settle_money")}'
                    , templet: myCommon.table.fn, fn: function (value, data) {
                        return myCommon.value(data, 'sign_money') + '<br>' + myCommon.value(data, 'undertake_money');
                    }
                }
                , {
                    field: 'settle_status', width: 75, title: '{:lang("contract.settle_status")}'
                    , templet: myCommon.table.fn, fn: function (value, data) {
                        return myCommon.getNameInType(myCommon.value(data, 'sign_status'), 'settle_status_list') + '<br>'
                            + myCommon.getNameInType(myCommon.value(data, 'undertake_status'), 'settle_status_list');
                    }
                }
                , {width: 50, title: '{:lang("common.operate")}', templet: myCommon.table.tool, operat: ['delete']}
            ]]
        });
        myCommon.listen();
    });
</script>
